import { IWork, IUser, IHistory } from '@lib/types';
import ajax from '@lib/ajax';

const URL = "work/get/";

interface IResponse {
	work: IWork;
	author: IUser;
	history: IHistory[];
}

export default async function(id: number, only_work: boolean = false) {
	let url = URL + id;
	if (only_work) {
		url += '?only_work=1'
	}
	const res = await ajax({
		url: url
	});
	if (res.success) {
		return res.data as IResponse;
	} else {
		return new Error(res.error);
	}
}